using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 尾巴
/// </summary>
public class PlayerTail : MonoBehaviour
{
    /// <summary>
    /// 蛇头
    /// </summary>
    public Transform networkedOwner;
    /// <summary>
    /// 跟随的对象
    /// </summary>
    public Transform followTransform;
    
    /// <summary>
    /// 延迟时间
    /// </summary>
    [SerializeField] private float delayTime = 0.5f;
    /// <summary>
    /// 移动步长
    /// </summary>
    [SerializeField] private float moveStep = 10f;
    
    /// <summary>
    /// 目标位置
    /// </summary>
    private Vector3 _targetPosition;

    private void Update()
    {
        // 跟随目标位置
        var followPos = followTransform.position;
        // 目标位置
        _targetPosition = followPos - (followPos - transform.position) * delayTime;
        // 移动
        transform.position = Vector3.Lerp(transform.position, _targetPosition, moveStep * Time.deltaTime);
        transform.up = followTransform.position - transform.position;
    }
}
